// <summary>
// 命令行参数配置类
// 用于定义和解析语音识别程序的各种配置参数
// </summary>
using CommandLine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SpeechRecognitionCSharp
{
    /// <summary>
    /// 语音识别配置选项类
    /// 包含所有可通过命令行配置的参数
    /// </summary>
    public class Options
    {
        /// <summary>
        /// 音频采样率
        /// 用于指定训练模型所用数据的采样率
        /// </summary>
        /// <remarks>
        /// 默认值: 16000 Hz
        /// 通常不需要修改，除非使用特殊采样率的模型
        /// </remarks>
        [Option("sample-rate", Required = false, Default = 16000, HelpText = "Sample rate of the data used to train the model")]
        public int SampleRate { get; set; } = 16000;

        /// <summary>
        /// 特征维度
        /// 用于指定训练模型所用的特征维度
        /// </summary>
        /// <remarks>
        /// 默认值: 80
        /// 通常与模型训练时使用的特征维度保持一致
        /// </remarks>
        [Option("feat-dim", Required = false, Default = 80, HelpText = "Dimension of the features used to train the model")]
        public int FeatureDim { get; set; } = 80;

        /// <summary>
        /// 词汇表文件路径
        /// 指定包含模型词汇表的tokens.txt文件路径
        /// </summary>
        /// <remarks>
        /// 该文件通常包含模型能够识别的所有词汇
        /// 是语音识别所必需的配置文件
        /// </remarks>
        [Option(Required = false, HelpText = "Path to tokens.txt")]
        public string Tokens { get; set; } = string.Empty;

        /// <summary>
        /// Transducer模型编码器路径
        /// 指定Transducer模型的encoder.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于Transducer类型的模型
        /// 与Decoder和Joiner配合使用
        /// </remarks>
        [Option(Required = false, Default = "", HelpText = "Path to transducer encoder.onnx. Used only for transducer models")]
        public string Encoder { get; set; } = string.Empty;

        /// <summary>
        /// Transducer模型解码器路径
        /// 指定Transducer模型的decoder.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于Transducer类型的模型
        /// 与Encoder和Joiner配合使用
        /// </remarks>
        [Option(Required = false, Default = "", HelpText = "Path to transducer decoder.onnx. Used only for transducer models")]
        public string Decoder { get; set; } = string.Empty;

        /// <summary>
        /// Transducer模型连接器路径
        /// 指定Transducer模型的joiner.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于Transducer类型的模型
        /// 用于连接编码器和解码器的输出
        /// </remarks>
        [Option(Required = false, Default = "", HelpText = "Path to transducer joiner.onnx. Used only for transducer models")]
        public string Joiner { get; set; } = string.Empty;

        /// <summary>
        /// 模型类型
        /// 指定使用的语音识别模型类型
        /// </summary>
        /// <remarks>
        /// 支持的模型类型包括: transducer, paraformer, nemo-ctc等
        /// 不同类型的模型需要不同的配置参数
        /// </remarks>
        [Option("model-type", Required = false, Default = "", HelpText = "model type")]
        public string ModelType { get; set; } = string.Empty;

        /// <summary>
        /// FireRedAsr模型编码器路径
        /// 指定FireRedAsr模型的encoder.int8.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于FireRedAsr类型的模型
        /// 与FireRedAsrDecoder配合使用
        /// </remarks>
        [Option("fire-red-asr-encoder", Required = false, Default = "", HelpText = "Path to FireRedAsr encoder.int8.onnx. Used only for FireRedAsr models")]
        public string FireRedAsrEncoder { get; set; } = string.Empty;


        /// <summary>
        /// FireRedAsr模型解码器路径
        /// 指定FireRedAsr模型的decoder.int8.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于FireRedAsr类型的模型
        /// 与FireRedAsrEncoder配合使用
        /// </remarks>
        [Option("fire-red-asr-decoder", Required = false, Default = "", HelpText = "Path to FireRedAsr decoder.int8.onnx. Used only for FireRedAsr models")]
        public string FireRedAsrDecoder { get; set; } = string.Empty;


        /// <summary>
        /// Whisper模型编码器路径
        /// 指定Whisper模型的encoder.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于Whisper类型的模型
        /// 与WhisperDecoder配合使用
        /// </remarks>
        [Option("whisper-encoder", Required = false, Default = "", HelpText = "Path to whisper encoder.onnx. Used only for whisper models")]
        public string WhisperEncoder { get; set; } = string.Empty;

        /// <summary>
        /// Whisper模型解码器路径
        /// 指定Whisper模型的decoder.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于Whisper类型的模型
        /// 与WhisperEncoder配合使用
        /// </remarks>
        [Option("whisper-decoder", Required = false, Default = "", HelpText = "Path to whisper decoder.onnx. Used only for whisper models")]
        public string WhisperDecoder { get; set; } = string.Empty;

        /// <summary>
        /// Whisper模型语言设置
        /// 指定输入文件的语言
        /// </summary>
        /// <remarks>
        /// 仅用于Whisper类型的模型
        /// 为空时模型会自动检测语言
        /// </remarks>
        [Option("whisper-language", Required = false, Default = "", HelpText = "Language of the input file. Can be empty")]
        public string WhisperLanguage { get; set; } = string.Empty;

        /// <summary>
        /// Whisper模型任务设置
        /// 指定模型执行的任务类型
        /// </summary>
        /// <remarks>
        /// 仅用于Whisper类型的模型
        /// 可选值: transcribe(转录) 或 translate(翻译)
        /// 默认值: transcribe
        /// </remarks>
        [Option("whisper-task", Required = false, Default = "transcribe", HelpText = "transcribe or translate")]
        public string WhisperTask { get; set; } = "transcribe";

        /// <summary>
        /// Moonshine模型预处理器路径
        /// 指定Moonshine模型的preprocess.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于Moonshine类型的模型
        /// 用于对输入音频进行预处理
        /// </remarks>
        [Option("moonshine-preprocessor", Required = false, Default = "", HelpText = "Path to preprocess.onnx. Used only for Moonshine models")]
        public string MoonshinePreprocessor { get; set; } = string.Empty;

        /// <summary>
        /// Moonshine模型编码器路径
        /// 指定Moonshine模型的encode.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于Moonshine类型的模型
        /// 与MoonshineUncachedDecoder和MoonshineCachedDecoder配合使用
        /// </remarks>
        [Option("moonshine-encoder", Required = false, Default = "", HelpText = "Path to encode.onnx. Used only for Moonshine models")]
        public string MoonshineEncoder { get; set; } = string.Empty;

        /// <summary>
        /// Moonshine模型非缓存解码器路径
        /// 指定Moonshine模型的uncached_decode.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于Moonshine类型的模型
        /// 与MoonshineEncoder和MoonshineCachedDecoder配合使用
        /// </remarks>
        [Option("moonshine-uncached-decoder", Required = false, Default = "", HelpText = "Path to uncached_decode.onnx. Used only for Moonshine models")]
        public string MoonshineUncachedDecoder { get; set; } = string.Empty;

        /// <summary>
        /// Moonshine模型缓存解码器路径
        /// 指定Moonshine模型的cached_decode.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于Moonshine类型的模型
        /// 与MoonshineEncoder和MoonshineUncachedDecoder配合使用
        /// </remarks>
        [Option("moonshine-cached-decoder", Required = false, Default = "", HelpText = "Path to cached_decode.onnx. Used only for Moonshine models")]
        public string MoonshineCachedDecoder { get; set; } = string.Empty;

        /// <summary>
        /// TDNN模型路径
        /// 指定TDNN (Time Delay Neural Network) 模型的文件路径
        /// </summary>
        /// <remarks>
        /// 用于yes/no识别任务
        /// </remarks>
        [Option("tdnn-model", Required = false, Default = "", HelpText = "Path to tdnn yesno model")]
        public string TdnnModel { get; set; } = string.Empty;

        /// <summary>
        /// Paraformer模型路径
        /// 指定Paraformer模型的model.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于Paraformer类型的模型
        /// </remarks>
        [Option(Required = false, HelpText = "Path to model.onnx. Used only for paraformer models")]
        public string Paraformer { get; set; } = string.Empty;

        /// <summary>
        /// NeMo CTC模型路径
        /// 指定NeMo CTC模型的model.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于NeMo CTC类型的模型
        /// CTC (Connectionist Temporal Classification) 是一种用于序列到序列学习的损失函数
        /// </remarks>
        [Option("nemo-ctc", Required = false, HelpText = "Path to model.onnx. Used only for NeMo CTC models")]
        public string NeMoCtc { get; set; } = string.Empty;

        /// <summary>
        /// Zipformer CTC模型路径
        /// 指定Zipformer CTC模型的model.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于Zipformer CTC类型的模型
        /// Zipformer是一种基于Transformer的语音识别模型架构
        /// </remarks>
        [Option("zipformer-ctc", Required = false, HelpText = "Path to model.onnx. Used only for Zipformer CTC models")]
        public string ZipformerCtc { get; set; } = string.Empty;

        /// <summary>
        /// Dolphin CTC模型路径
        /// 指定Dolphin CTC模型的文件路径
        /// </summary>
        /// <remarks>
        /// Dolphin是一种语音识别模型
        /// </remarks>
        [Option("dolphin-model", Required = false, Default = "", HelpText = "Path to dolphin ctc model")]
        public string DolphinModel { get; set; } = string.Empty;

        /// <summary>
        /// TeleSpeech CTC模型路径
        /// 指定TeleSpeech CTC模型的model.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于TeleSpeech CTC类型的模型
        /// </remarks>
        [Option("telespeech-ctc", Required = false, HelpText = "Path to model.onnx. Used only for TeleSpeech CTC models")]
        public string TeleSpeechCtc { get; set; } = string.Empty;

        /// <summary>
        /// SenseVoice CTC模型路径
        /// 指定SenseVoice CTC模型的model.onnx文件路径
        /// </summary>
        /// <remarks>
        /// 仅用于SenseVoice CTC类型的模型
        /// </remarks>
        [Option("sense-voice-model", Required = false, HelpText = "Path to model.onnx. Used only for SenseVoice CTC models")]
        public string SenseVoiceModel { get; set; } = string.Empty;

        /// <summary>
        /// SenseVoice模型是否使用文本逆标准化
        /// 指定是否为SenseVoice模型启用文本逆标准化
        /// </summary>
        /// <remarks>
        /// 默认值: 1 (启用)
        /// 文本逆标准化用于将模型输出的文本转换为更自然的语言形式
        /// </remarks>
        [Option("sense-voice-use-itn", Required = false, HelpText = "1 to use inverse text normalization for sense voice.")]
        public int SenseVoiceUseItn { get; set; } = 1;

        /// <summary>
        /// 计算线程数
        /// 指定用于模型计算的线程数量
        /// </summary>
        /// <remarks>
        /// 默认值: 1
        /// 增加线程数可以提高处理速度，但可能会增加CPU使用率
        /// </remarks>
        [Option("num-threads", Required = false, Default = 1, HelpText = "Number of threads for computation")]
        public int NumThreads { get; set; } = 1;

        [Option("decoding-method", Required = false, Default = "greedy_search",
                HelpText = "Valid decoding methods are: greedy_search, modified_beam_search")]
        public string DecodingMethod { get; set; } = "greedy_search";

        /// <summary>
        /// 规则FST文件路径
        /// 指定用于文本逆标准化的规则FST文件路径
        /// </summary>
        /// <remarks>
        /// FST (Finite State Transducer) 用于实现文本转换规则
        /// 如果为空，则不使用额外的文本逆标准化规则
        /// </remarks>
        [Option("rule-fsts", Required = false, Default = "",
                HelpText = "If not empty, path to rule fst for inverse text normalization")]
        public string RuleFsts { get; set; } = string.Empty;

        /// <summary>
        /// 最大活动路径数
        /// 指定在束搜索过程中保留的活动路径数量
        /// </summary>
        /// <remarks>
        /// 默认值: 4
        /// 仅在decoding-method设置为modified_beam_search时使用
        /// 增加此值可以提高识别准确性，但会增加计算量
        /// </remarks>
        [Option("max-active-paths", Required = false, Default = 4,
            HelpText = @"Used only when --decoding--method is modified_beam_search.
It specifies number of active paths to keep during the search")]
        public int MaxActivePaths { get; set; } = 4;

        /// <summary>
        /// 热词文件路径
        /// 指定包含热词列表的hotwords.txt文件路径
        /// </summary>
        /// <remarks>
        /// 热词是需要优先识别的词汇
        /// 如果为空，则不使用热词
        /// </remarks>
        [Option("hotwords-file", Required = false, Default = "", HelpText = "Path to hotwords.txt")]
        public string HotwordsFile { get; set; } = string.Empty;

        /// <summary>
        /// 热词权重
        /// 指定热词在识别过程中的权重
        /// </summary>
        /// <remarks>
        /// 默认值: 1.5
        /// 较高的值会增加热词被识别的概率
        /// </remarks>
        [Option("hotwords-score", Required = false, Default = 1.5F, HelpText = "hotwords score")]
        public float HotwordsScore { get; set; } = 1.5F;

        /// <summary>
        /// 音频文件路径
        /// 指定要进行解码的音频文件路径列表
        /// </summary>
        /// <remarks>
        /// 这是必需参数
        /// 支持传入多个文件路径
        /// </remarks>
        [Option("files", Required = true, HelpText = "Audio files for decoding")]
        public IEnumerable<string> Files { get; set; } = new string[] { };
    }


}
